<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择成语</title>
    <script src="./js/jQuery.min.js"></script>
</head>
<style>
    * {
        padding: 0;
        margin: 0;
    }

    .all {
        width: 600px;
        height: 600px;
        margin: 100px auto;
        position: relative;
    }

    .top {
        width: 550px;
        height: 120px;
        margin: auto;
        position: absolute;
    }

    ul {
        width: 550px;
        height: 460px;
        position: absolute;
        bottom: 0;
        left: 45%;
        transform: translateX(-50%);
    }

    ul li {
        list-style: none;
        float: left;
        margin: 10px;
        width: 90px;
        height: 36px;
        background-color: aqua;
        border-radius: 30px;
        text-align: center;
        line-height: 36px;
        cursor: pointer;

    }

    .chengyu {
        width: 150px;
        height: 40px;
        position: absolute;
        left: 30%;
        top: 5px;
        background-color: pink;
        border-radius: 30px;
        text-align: center;
        line-height: 40px;
    }

    .cont {
        width: 200px;
        height: 40px;
        background-color: aqua;
        text-align: center;
        line-height: 30px;
        position: absolute;
        left: 25%;
        bottom: 0;
        border-radius: 30px;

    }

    button {
        position: absolute;
        left: 60%;
        top: 10px;

    }
</style>

<body>
    <div class="all">
        <div class="top">
            <div class="chengyu"></div>
            <button>换一个</button>
            <div class="cont"></div>
        </div>
        <ul></ul>
    </div>
    <script>
        let str = '天下第一理所当然引人注目独一无二脱颖而出全心全意淋漓尽致千方百计自然而然轻而易举';
        let arr = str.split("");
        let lis = '';
        for (let i = 0; i < arr.length; i++) {
            lis += `<li></li>`;
        }
        $('ul').append(lis);
        changeCon();

        $('button').click(function () {
            changeCon();
            $('.cont').text('');
            str1 = '';
        })
        var str1 = '';
        $('li').click(function () {
            if (str1.length < 4) {
                str1 += $(this).text();
                $('.cont').text(str1);
                if ($('.chengyu').text() == str1) {
                    changeCon();
                    $('.cont').text('');
                    str1 = '';
                    alert('全选对了');
                }
            } else {
                alert('再来一次')
                $('.cont').text('');
                str1 = '';
                changeCon();
            }

        })

        function changeCon() {
            arr1 = [];
            for (let i = 0; i < 1000; i++) {
                let num = Math.floor(Math.random() * arr.length);
                if (arr1.indexOf(num) < 0) {
                    arr1.push(num);
                }
            }

            let y = 0;
            for (let x = 0; x < 40; x++) {
                $('li').eq(y).text(arr[arr1[x]]);
                y++;
            }

            arr2 = [];
            for (let i = 0; i < 1000; i++) {
                let num = Math.floor(Math.random() * arr.length / 4);
                if (arr2.indexOf(num) < 0) {
                    arr2.push(num);
                }
            }
            for (let x = 0; x < arr1.length / 4; x++) {
                $('.chengyu').text(str.slice(arr2[x] * 4, arr2[x] * 4 + 4))
            }

        }



    </script>
</body>

</html>